<template>
	<view class="container">
		<view class="zs">
			<uni-segmented-control :current="current" :values="items" style-type="text" active-color="#FA2C1E"
			 @clickItem="onClickItem"  style="background-color: #fff;"/>
			 <view class="list">
			 	<view class="card other_info" v-for="(item,index) in cardlogList" :key="index">
			 		<view class="card_top">
			 			<view class="card_title"> 时间 </view>
						<view class="card_title_right"> {{item.createtime}} </view>
			 		</view>
			 		<view class="card_content">
			 			<view class="cell">
			 				<view class="label"> 产品名称 </view>
			 				<view class="value"> {{item.name}} </view>
			 			</view>
			 			<view class="cell">
			 				<view class="label"> 赠送人手机号 </view>
			 				<view class="value"> {{item.mobile}} </view>
			 			</view>
			 			<view class="cell">
			 				<view class="label"> 48小时是否使用 </view>
			 				<view class="value"> {{statusMap[item.is_use]}} </view>
			 			</view>
			 		</view>
					<view class="card_bottom">
						<button class="btn">查看详情</button>
					</view>
			 	</view>
				<uni-load-more :status="status" :content-text="contentText" />
			 </view>
		</view>
	</view>
</template>

<script>
	import {cardlog} from '../../../api/api.js'
	export default {
		data() {
			return {
				current:0,
				items: ['赠送记录', '接受记录'],
				page:1,
				cardlogList:[],
				statusMap:{
					'0':'未使用',
					'1':'已使用'
				},
				status:'more',
				statusTypes: [{
					value: 'more',
					text: '加载前',
					checked: true
				}, {
					value: 'loading',
					text: '加载中',
					checked: false
				}, {
					value: 'noMore',
					text: '没有更多',
					checked: false
				}],
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			}
		},
		onLoad(options) {
			this.getCardlog()
		},
		onReachBottom(){  //上拉触底函数
			if(!this.isLoadMore){  //此处判断，上锁，防止重复请求
				this.isLoadMore=true
				this.page+=1
				this.getCardlog()
			}
		},
		methods:{
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					this.page = 1
					this.cardlogList = []
					this.getCardlog()
				}
			},
			getCardlog(){
				this.status = 'loading'
				cardlog({status:this.current,page:this.page,limit:15}).then(res=>{
					console.log(res)
					this.cardlogList.push(...res.data.data.data)
					console.log(this.cardlogList.length,res.data.data.total)
					if(this.cardlogList.length >= res.data.data.total){
						this.status = 'noMore'
					}else {
						this.status = 'more'
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: calc(100vh - 88rpx);
		background: #F8F8F8;
		/deep/.segmented-control {
			background-color: #fff;
		}
	}
	.list {
		padding: 0 24rpx;
	}
	.card {
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 20rpx 30rpx;
		margin-top: 24rpx;
		.card_top {
			height: 82rpx;
			padding-bottom: 20rpx;
			margin-bottom: 10rpx;
			border-bottom: 2rpx solid #E7E7E7;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.card_title {
				font-size: 26rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: #222222;
			}
			.card_title_right {
				font-size: 26rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: #222222;
			}
		}
		.card_content {
			.cell {
				display: flex;
				// align-items: center;
				font-size: 26rpx;
				line-height: 36rpx;
				padding: 10rpx 0;
				.label {
					flex: 1;
					color: #333333;
				}
				.value {
					flex: 2;
					text-align: right;
					color: #222222;
				}
			}
		}
		.card_bottom {
			margin-top: 12rpx;
			.btn {
				width: 170rpx;
				height: 60rpx;
				border-radius: 30rpx;
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				line-height:60rpx;
				float: right;
				margin-left: 20rpx;
				border: 1px solid #D1D2D5;
				background-color: #fff;
				color: #666666;
			}
			.btn::after{
				content:none;
				border:none
			}
		}
		.card_bottom::after{clear:both;content:'';display:block;}
	}
</style>
